window.onload = function() {
    var checked;
    var _count = (localStorage.getItem('count') && JSON.parse(localStorage.getItem('count'))) || '',
        _remember = (localStorage.getItem('count') &&JSON.parse(localStorage.getItem('remember'))) || '',
        loginBtn = document.getElementsByClassName('login')[0],
        rememberBtn = document.getElementById('remember'),
        user = document.getElementsByClassName('user'),
        pwd = document.getElementsByClassName('pwd'),
        errorMsg = document.getElementsByClassName('errorMsg');
    if (_count && _remember) {
        var thisDate = Date.parse(new Date());
        rememberBtn.checked = true;
        if (thisDate - _count.date > 1000 * 60 * 60 * 24 * 2) {
            errorMsg[0].innerHTML = '您的账号已过期，请重新输入!'
        } else {
            user[0].value = _count.user;
            pwd[0].value = _count.pwd;
        }
    }
    loginBtn.onclick = function() {
        if (user[0].value == 'admin') {
            if (pwd[0].value == 'oaTwXcP7') {
                var count = {};
                if (checked) {
                    count.user = user[0].value;
                    count.pwd = pwd[0].value;
                    count.date = Date.parse(new Date());
                    count = JSON.stringify(count);
                    localStorage.setItem('count', count)
                    localStorage.setItem('remember', true)
                } else {
                    count.date = Date.parse(new Date());
                    count = JSON.stringify(count);
                    localStorage.setItem('count', count)
                    localStorage.setItem('remember', false)
                }
                location = window.location.search.replace(/\?url=/, '')
            } else {
                errorMsg[0].innerHTML = '您输入的密码有误，请重新输入!'
            }

        } else if (!!user[0].value && user[0].value != 'admin') {
            errorMsg[0].innerHTML = '您输入的账号有误，请重新输入!'
        } else {
            errorMsg[0].innerHTML = '请输入账号!'
        }
    }
    rememberBtn.onchange = function() {
        checked = this.checked;
        if (checked) {
            localStorage.setItem('remember', true)
        } else {
            localStorage.setItem('remember', false)
        }
    }
}
